package com.example.baguwen;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@SpringBootApplication
@EnableJpaAuditing
@RestController
public class BaguwenApplication {

    public static void main(String[] args) {
        SpringApplication.run(BaguwenApplication.class, args);
    }
    
    @GetMapping("/test")
    public String test() {
        return "应用正常运行!";
    }
    
    @PostMapping("/api/direct-login")
    public Map<String, Object> directLogin(@RequestBody Map<String, String> loginData) {
        Map<String, Object> result = new HashMap<>();
        Map<String, Object> userData = new HashMap<>();
        
        // 简单的模拟登录
        String username = loginData.get("username");
        String password = loginData.get("password");
        
        System.out.println("直接登录尝试: " + username + "/" + password);
        
        if ("admin".equals(username) && "123456".equals(password)) {
            userData.put("id", 1);
            userData.put("username", username);
            userData.put("nickname", "管理员");
            userData.put("token", "test-token-" + System.currentTimeMillis());
            
            result.put("code", 200);
            result.put("message", "登录成功");
            result.put("data", userData);
        } else {
            result.put("code", 400);
            result.put("message", "用户名或密码错误");
            result.put("data", null);
        }
        
        return result;
    }
} 